﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace TalentDesk.Contracts.DataContracts
{
    [DataContract]
    public abstract class BaseValidateableObject : BaseNotifyObject
    {
        protected override bool SetValue<T>(ref T target, T value, string propertyName)
        {
            if ((target != null) && (Object.Equals(target, value)))
            {
                return false;
            }

            Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = propertyName });
            target = value;
            RaisePropertyChanged(propertyName);
            return true;
        }
    }
}
